package spring.boot.kafka.controller;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.apache.logging.log4j.LogManager;


@RestController
@RequestMapping("/dev")
public class DevController {
    protected final Logger log = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private KafkaTemplate kafkaTemplate;
    @RequestMapping("/send")
    public void send(){
        String message = "测试kakfa："+System.currentTimeMillis();
        ListenableFuture future = kafkaTemplate.send("test",message);
        future.addCallback(o -> log.info("send-消息发送成功：" + message), throwable -> log.error("消息发送失败：" + message));
    }

    @RequestMapping("/log")
    public String log(@RequestParam(required = false) String info){
        String message = "测试 kakfa LOG4J："+info+System.currentTimeMillis();
        log.info(message);
        return "log";
    }

}
